package com.orivon.mob.hook.helper;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;

import de.robv.android.xposed.XposedBridge;

public class HookProvider extends ContentProvider {
    public HookProvider() {
    }


    private final static String AUTHORITIES = "com.orivon.mob.hook.mm";
    private final static int DICE = 1;
    private final static int MORRA = 2;
    private static MyDatabaseHelpser mMyDatabaseHelpser;


    private static UriMatcher mUriMatcher;


    static {
        mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        mUriMatcher.addURI(AUTHORITIES, "wt_data", DICE); // 骰子
        mUriMatcher.addURI(AUTHORITIES, "wt_data/#", DICE); // 骰子
        mUriMatcher.addURI(AUTHORITIES, "wt_data", MORRA); // 猜拳
        mUriMatcher.addURI(AUTHORITIES, "wt_data/#", MORRA); // 猜拳


    }


    @Override
    public boolean onCreate() {
        mMyDatabaseHelpser = new MyDatabaseHelpser(getContext());


        return (mMyDatabaseHelpser == null) ? false : true;
    }

    @Override
    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
        System.out.println("a->" + projection[0]);

        if (projection[0].equals(MyDatabaseHelpser.TABLE_NAME)) {
            return DaoHandler.getInstance(getContext()).query(null, selection, selectionArgs, sortOrder);
        } else {
            return DaoHandler.getInstance(getContext()).getSupVer(null, selection, selectionArgs, sortOrder);
        }
    }

    @Override
    public String getType(Uri uri) {
        return "vnd.android.cursor.dir/vnd." + AUTHORITIES + "." + MyDatabaseHelpser.TABLE_NAME;
    }

    @Override
    public Uri insert(Uri uri, ContentValues values) {

        return null;
    }

    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        return DaoHandler.getInstance(getContext()).delectNum(Integer.parseInt(selectionArgs[0]));
    }

    @Override
    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
        // TODO Auto-generated method stub
        return 0;
    }
}
